home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / doc / LPC / operators < prev    next >
Text File  |  2001-07-16  |  8KB  |  189 lines

  1. NAME
  2.         operators
  3.  
  4. DESCRIPTION
  5.  
  6.         These are the operators availailable in LPC. They are listed
  7.         in the order of precedence (low priority first):
  8.  
  9.  
  10.         expr1 , expr2        Evaluate 'expr1' and then 'expr2'. The
  11.                         returned value is the result of 'expr2'. The
  12.                         returned value of 'expr1' is thrown away.
  13.  
  14.         var = expr        Evaluate 'expr', and assign the value to
  15.                         'var'. The new value of 'var' is the result.
  16.  
  17.         var += expr        Assign the value of 'expr' + 'var' to 'var'.
  18.                         This is equivalente to "var = var + expr".
  19.  
  20.         var -= expr        Similar to '+=' above.
  21.         var &= expr
  22.         var |= expr
  23.         var ^= expr
  24.         var <<= expr
  25.         var >>= expr
  26.         var >>>= expr
  27.         var *= expr
  28.         var %= expr
  29.         var /= expr
  30.  
  31.         expr1 ? expr2 : expr3
  32.                         Evaluates 'expr1' and branches according to
  33.                         its truth value. If it is true, the 'expr2' is
  34.                         evaluated and returned as result, else
  35.                         'expr3'.
  36.  
  37.         expr1 || expr2        The result is true if 'expr1' or 'expr2' is
  38.                         true. 'expr2' is not evaluated if 'expr1' was
  39.                         true.
  40.  
  41.         expr1 && expr2        The result is true i 'expr1' and 'expr2' is
  42.                         true. 'expr2' is not evaluated if 'expr1' was
  43.                         false.
  44.  
  45.         expr1 | expr2        The result is the bitwise or of 'expr1' and
  46.                         'expr2'.
  47.  
  48.         expr1 ^ expr2        The result is the bitwise xor of 'expr1' and
  49.                         'expr2'.
  50.  
  51.         expr1 & expr2        The result is the bitwise and of 'expr1' and
  52.                         'expr2'.
  53.                         For arrays and strings, the intersection set
  54.                         (all elements resp. characters from expr1 which
  55.                         which are also in the expr2) is computed.
  56.  
  57.         expr1 == expr2        Compare values. Valid for strings, numbers,
  58.                               objects and closures.
  59.  
  60.         expr1 != expr1        Compare values. Valid for strings, numbers,
  61.                               objects and closures.
  62.  
  63.         expr1 > expr2        Valid for strings and numbers.
  64.  
  65.         expr1 >= expr2        Valid for strings and numbers.
  66.  
  67.         expr1 < expr2        Valid for strings and numbers.
  68.  
  69.         expr1 <= expr2        Valid for strings and numbers.
  70.  
  71.         expr1 << expr2        Shift 'expr1' left by 'expr2' bits.
  72.  
  73.         expr1 >> expr2        Shift 'expr1' right by 'expr2' bits.
  74.                         This shift preserves the sign of 'expr1'.
  75.  
  76.         expr1 >>> expr2        Shift 'expr1' right by 'expr2' bits.
  77.                         This shift does not preserve the sign of 'expr1',
  78.                         instead it shifts in 0 bits.
  79.  
  80.         expr1 + expr2        Add 'expr1' and 'expr2'. If numbers, then
  81.                         arithmetic addition is used. If one of the
  82.                         expressions are a string, then that string is
  83.                         concatenated with the other value.
  84.                         If the expressions are arrays, the result is
  85.                         the right array appended to the left.
  86.                         If the expressions are mappings of equal width,
  87.                         the result is merger of the two mappings. If one
  88.                         key exists in both mappings, the element from the
  89.                         right mapping appears in the result. If the two
  90.                         mappings are of different width, the result is
  91.                         <expr1> if non-empty, and <expr2> otherwise.
  92.  
  93.         expr1 - expr2        Subtract 'expr2' from 'expr1'. Valid for
  94.                         numbers, strings, arrays, mappings.
  95.                         For arrays and strings, all occurences of the
  96.                         elements resp. characters in 'expr2' are removed
  97.                         from 'expr1', and the result is returned.
  98.                         For mapping, all occurances of elemens in 'expr1'
  99.                         which have a matching key in 'expr2' are removed, and
  100.                         the result is returned.
  101.  
  102.         expr1 * expr2        Multiply 'expr1' with 'expr2'.
  103.                         If strings or arrays are multiplied with a number
  104.                         (zero or positive), the result is a repetition of the
  105.                         original string or array.
  106.  
  107.         expr1 % expr2        The modulo operator of numeric arguments.
  108.  
  109.         expr1 / expr2        Integer division.
  110.  
  111.         ++ var                Increment the value of variable 'var', and
  112.                         return the new value.
  113.  
  114.         -- var                Decrement the value of variable 'var', and
  115.                         return the new value.
  116.  
  117.         - var                Compute the negative value of 'var'.
  118.  
  119.         ! var                Compute the logical 'not' of an integer.
  120.  
  121.         ~ var                The boolean 'not' of an integer.
  122.  
  123.         ( type ) var    Return the value of <var> converted to <type>.
  124.                         <type> can be 'string', 'int', 'object', 'float'
  125.                         or 'int*'. <var> must be of a specific type 
  126.                         for a conversion to take place; if <var> is 'mixed'
  127.                         or unknown, the cast is purely declarative.
  128.                         Also, if the type of <var> is that of <type>, the
  129.                         value is not changed.
  130.                         
  131.                         NB. The literal number 0 is of unknown type, as
  132.                         it doubles as 'not initialized' for strings, objects,
  133.                         and arrays.
  134.                         
  135.                         The operator acts like the efuns
  136.                         to_string(), to_int(), to_object(), to_float()
  137.                         and to_array(). It is advisable to use the
  138.                         efuns directly instead of the cast.
  139.  
  140.         ({ type }) var  <var> is now assumed to have the type <type>.
  141.                         This is purely declarative, the actual value
  142.                         of <var> is not changed.
  143.  
  144.         var ++                Increment the value of variable 'var', and
  145.                         return the old value.
  146.  
  147.         var --                Decrement the value of variable 'var', and
  148.                         return the old value.
  149.  
  150.         expr1[expr2]        The array or mapping given by 'expr1' is
  151.                         indexed by 'expr2'.
  152.  
  153.         expr1[expr2..expr3] Extracts a
  154.                         piece from an array or string.
  155.                         expr2 or expr3 may be omitted, default is the begin
  156.                         or end of expr1.
  157.                         Negative numbers for expr2 or expr3
  158.                         mean ``count from before the beginning'', i.e.
  159.                         foo[-2..-1] is an empty array or string.
  160.                         foo[<2..<1] gives the 2nd and last element of
  161.                         the array resp. chars of the string.
  162.  
  163.         expr1->name(...) The symbolic form of call_other(). 'expr1'
  164.                         gives either an object or a string which is
  165.                         used as the file_name of an object, and calls
  166.                         the function 'name' in this object.
  167.  
  168.         ident::name(...)
  169.                         Call the inherited function 'name' with the
  170.                         given parameters in the parent 'ident'.
  171.                         'ident' may be given as string containing the
  172.                         full pathname, or as identifier containing the
  173.                         pure basename.
  174.                         If 'ident' is omitted, the last inherited
  175.                         function of this 'name' is called.
  176.  
  177.         ({ })                Array constructor.
  178.         ([ ])                Mapping constructor.
  179.  
  180. NOTE
  181.         The closure operators are not described here.
  182.  
  183. HISTORY
  184.         LDMud 3.2.9 added '>>>' and '>>>='.
  185.  
  186. SEE ALSO
  187.         arrays(LPC), alists(LPC), mappings(LPC), closures(LPC)
  188.  
  189.